# Scanner makefile

# Allow compiling as Lib
BuildScannerLib=Compile_As_Lib

# Make sure we can clean on windows as well
# Disable compile warnings
ifdef SystemRoot
   RM = del /Q /F
   ifdef BuildScannerLib
   FPIC =
   endif
   LIBS =  ../Puffer/Buffer.o ../Symtable/*.o
else
   ifeq ($(shell uname), Linux)
      RM = rm -f
      ifdef BuildScannerLib
      FPIC = -fPIC
      endif
      LIBS = -L../Puffer -L../Symtable -lBuffer -lSymtable
   endif
endif

ifdef BuildScannerLib
CXXFLAGS =	-O2 -Wall $(FPIC) -c
LDFLAGS =	-shared -Wl,-soname,libScanner.so
else
CXXFLAGS =	-O2 -Wall -c
LDFLAGS =
endif

SRC =		main.cpp Scanner.cpp Automat.cpp Token.cpp State.cpp Output.cpp
OBJS =		$(SRC:.cpp=.o)
INCS =		$(wildcard *.h)

ifdef BuildScannerLib
TARGET =	libScanner.so
else
TARGET =	scanner
endif


$(TARGET):	$(OBJS)
	$(CXX) $(LDFLAGS) -o $(TARGET) $(OBJS) $(LIBS)

%.o: %.cpp $(INCS)
	$(CXX) $(CXXFLAGS) $< -o $@

debug:	CXX += -DDEBUG -g
debug:	CC += -DDEBUG -g
debug:	all

release:	all

all:	$(SRC) $(TARGET)

.PHONY: clean
clean:
	$(RM) $(OBJS) $(TARGET)
